package com.eairlv.cli.config;

import com.google.common.base.Predicate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static com.google.common.base.Predicates.or;
import static springfox.documentation.builders.PathSelectors.ant;

/**
 * @author lv
 * @create 2018-04-27 18:51
 * @desc Swagger 配置
 **/

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createDocket(){
        Predicate<String> path = or(ant("/cli/**"));
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("eairlv-cli")
                .useDefaultResponseMessages(false)
                .forCodeGeneration(false)
                .apiInfo(apiInfo())
                .select()
                .paths(path)
                .build();
    }

    /**
     * 接口描述
     */
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("eairlv-cli")
                .description("eairlv-cli 脚手架工具swagger2接口文档")
                .termsOfServiceUrl("https://gitee.com/eairlv")
                .license("Apache License Version 1.0")
                .licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE")
                .version("1.0")
                .build();
    }
}
